package com.qf.servlet;

import com.github.pagehelper.PageInfo;
import com.qf.entity.User;
import com.qf.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.servlet
 * @Description:
 * @Date 2022/9/30 19:27
 */
@SuppressWarnings("all")
//@RestController
@Controller
public class UserServlet {

    @Autowired
    Service service;

    @RequestMapping("/find")
    @ResponseBody
    public List<User> findAll(){
        List<User> users = service.selsectAll();
        return users;
    }


    @RequestMapping("/users")
    public String findByPage(ModelMap modelMap,
                             @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize){
        PageInfo<User> pageInfo = service.findByPage(pageNum,pageSize);
        modelMap.put("data",pageInfo);
//        mv.addObject("data",pageInfo);
//        mv.setViewName("forward:/list.jsp");
//        model.addAttribute("data",pageInfo);
        return "forward:/list.jsp";
//        return mv;
    }
}
